﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace HasuSLUI
{
    public class MetaGroup
    {
        // SortedList<string, subGroupList> mlist = new SortedList<string, subGroupList>(); // not avialable in silverlight
        Dictionary<string, subMetaGroup> metaGroupList = new Dictionary<string, subMetaGroup>();

        string[] arMetaGroup = new string[0];

        public void Add(Metadata metadata)
        {
            if (!metaGroupList.ContainsKey(metadata.GroupName))
            {
                metaGroupList.Add(metadata.GroupName, new subMetaGroup());

                string[] tmpArr = new string[arMetaGroup.Length + 1];
                Array.Copy(arMetaGroup, tmpArr, arMetaGroup.Length);
                tmpArr[arMetaGroup.Length] = metadata.GroupName;

                arMetaGroup = tmpArr;
            }

            subMetaGroup tmpsgpList = metaGroupList[metadata.GroupName];
            tmpsgpList.Add(metadata);
        }

        public List<Metadata> getCollection()
        {
            List<Metadata> tmplist = new List<Metadata>();

            Array.Sort(arMetaGroup);

            foreach (string strKey in arMetaGroup)
            {
                foreach (Metadata metadata in metaGroupList[strKey].list)
                {
                    tmplist.Add(metadata);
                }
            }

            return tmplist;
        }

        class subMetaGroup
        {
            public List<Metadata> list = new List<Metadata>();

            public void Add(Metadata metadata)
            {
                list.Add(metadata);
            }
        }
    }
}
